<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/static/include/top.jsp"%>

<script>document.title="${title}";</script>
<script src="${baseURL}/static/js/My97DatePicker/WdatePicker.js"></script>
<script src="${baseURL}/static/js/jquery.easyui.min.js"></script>
<link href="${baseURL}/static/js/themes/default/easyui.css" rel="stylesheet" type="text/css" />



<c:set var="userAreaId" value="${sessionScope.user.userAreaId}"></c:set>
<c:set var="pid" value="${requestScope.areasMap[sessionScope.user.userAreaId].parentId}"></c:set>

<style type="text/css">
<!--
table {
	margin:0;
	width:auto;
	font-family:"微软雅黑";
	font-size:12px;
	color: #FFF;
	border-collapse: collapse;
}
//-->
</style>

<table id="search_t" style="width:98%">
		<tbody>
			<tr>
				<th><img src="${ctx}/static/images/pages/cen/rig/ico_01.png" align="middle">&nbsp;指标查询
				</th>
			</tr>
			<tr class="tab_grey">
				<td>
				<form name="searchForm" action="${baseURL}/audit/queryIndicatorToPage" method="post">
					<input type="hidden" name="p" value="1" />
					<input type="hidden" id="indicatorListData" name="indicatorListData" value="">
					<input type="hidden" id="areaId" name="areaId" value="${userAreaId}">
					<input type="hidden" id="timeType" name="timeType" value="1">
					<input type="hidden" id="yearTime" name="yearTime" value="2">
					选择条件：
				
				<c:choose>
					<c:when test="${pid eq '0'}">
						<span class="tab_text">省(自治区、直辖市):</span>
					</c:when>
					<c:when test="${requestScope.areasMap[pid].parentId eq '0'}">
						<span class="tab_text">地(区、市、州、盟):</span>
					</c:when>
					<c:otherwise>
						<span class="tab_text">县(区、市、旗):</span>
					</c:otherwise>
				</c:choose>
				
				<input type="text" class="tab_textbut" value="${sessionScope.user.userAreaName}" readonly>

				<c:if test="${pid eq '0'}">
					<span class="tab_text">地(区、市、州、盟):</span>
					<select class="tab_textbut" id="areaId2" onchange="queryAreasByParent(this)">
						<option value="">请选择..</option>
						<option value="${requestScope.areasMap['320600000000000'].id}">${requestScope.areasMap['320600000000000'].areaName}</option>
						<option value="${requestScope.areasMap['320700000000000'].id}">${requestScope.areasMap['320700000000000'].areaName}</option>
						<option value="${requestScope.areasMap['320900000000000'].id}">${requestScope.areasMap['320900000000000'].areaName}</option>
					</select>
				</c:if>

				<c:if test="${pid eq '0' || requestScope.areasMap[pid].parentId eq '0'}">
					<span class="tab_text">县(区、市、旗):</span>
					<select class="tab_textbut_100" id="areaId3">
						<option value="">请选择..</option>
						
						<c:if test="${requestScope.areasMap[pid].parentId eq '0'}">
							<c:forEach items="${requestScope.areasMap}" var="area">
								<c:if test="${requestScope.areasMap[pid].id eq area.value.parentId}">
								<option value="${area.value.id}">${area.value.areaName}</option>								
								</c:if>
							</c:forEach>
						</c:if>
						
					</select>
				</c:if>
				<span class="tab_text">单位类型：</span>
				<select id="unitType" name="unitType" class="tab_textbut">
					<option value="">请选择..</option>
					<c:forEach var="role" items="${roleList}">
						<option value="${role.id}">${role.roleName}</option>
					</c:forEach>
				</select> 
				
				<br/>
				
				<a class="tab_but" id="selectIndicator" href="#" onclick="selectIndicator();">选择指标</a>
				
				<span class="tab_text">起始年份:</span>
				<select id="startYear" name="startYear" class="tab_textbut">
					<option value="">请选择..</option>
				</select>        
		        <span class="tab_text">终止年份:</span>
				<select id="endYear" name="endYear" class="tab_textbut">
					<option value="">请选择..</option>
				</select>
				
				<a class="tab_but" href="#" onclick="queryData();">查询</a>
				<a class="tab_but" href="#" onclick="clearInput(); return false;">清空结果</a>
				<a class="tab_but" href="#" onclick="submitSelects();return false;">下载结果</a>
					
			</form>
				</td>
			</tr>
		</tbody>
</table>

<div id="nodata">
	<b>没有符合条件的记录。</b>
</div>
<br>
<div id="dataList">
<table id="dg" style="width:98%"></table>
</div>

<script language="javaScript">

	$().ready(function(){

		var startYear = ${requestScope.versionYearList.startYear};
		var endYear = ${requestScope.versionYearList.endYear};
		
		for (var i=endYear; i>=startYear; i--){
			$("#startYear").append("<option>" + i + "</option>");
			$("#endYear").html($("#startYear").html());
		}		
	});
	
	function validate(){
		if ($("#indicatorListData").val()==""){
			layer.tips('请选择查询指标', '#selectIndicator' , {guide: 1, time: 2});
			return;
		}
		if ($("#startYear").val()==""){
			layer.alert("请选择起始年份");
			return;
		}
		
		if ($("#endYear").val()==""){
			layer.alert("请选择终止年份");
			return;
		}
		
		$("#areaId").val("${userAreaId}");
		
		if ($("#areaId2").val()!="" && $("#areaId2").val() != undefined){
			$("#areaId").val($("#areaId2").val());
		}
		
		if ($("#areaId3").val()!="" && $("#areaId3").val() != undefined){
			$("#areaId").val($("#areaId3").val());
		}
		return true;
	}
	
	
	function submitSelects(){
		if (!validate()){
			return;
		}
		
		searchForm.action = "${baseURL}/audit/importIndicatorNew";
		searchForm.submit();
	}
	
	
	//表单提交查询
	function queryData(){

		if (!validate()){
			return;
		}

		var url = "${baseURL}/audit/queryIndicator";
		var data = "indicatorListData=" + $("#indicatorListData").val() + "&startYear=" + $("#startYear").val() + "&endYear=" + $("#endYear").val()
		         + "&areaId=" + $("#areaId").val() + "&timeType=" + $("#timeType").val() + "&yearTime=" + $("#yearTime").val() + "&unitType=" + $("#unitType").val();

		var columns = new Array();
		var col = new Array();
		var loadi;

		$.ajax({
			url: url,
			type: 'post',
			data: data,
			dataType: 'json',
			beforeSend: function(){
				loadi = layer.load('加载中…');
			},
			complete: function(){
				layer.close(loadi);
			},
			success: function(msg){
				
				if (msg.code==500){
					$("#nodata").css("display", "");
					$("#dataList").css("display", "none");
					layer.msg("查询失败", 1);
					return;
				}else{
					$("#nodata").css("display", "none");
					$("#dataList").css("display", "");
				}
				
				$.each(msg.head, function(i, head){
					var width = 100;
					
					if (i<2){
						width = 250;
					}
					col.push({'field':head, 'title':head, width:width});
				});
				
				columns.push(col);

				var rowsJson = eval('(' + msg.queryResult + ')');

				$('#dg').treegrid({    
				    data:rowsJson,    
		  			idField:'id',
		  			treeField:'地区名称',
		  			nowrap:true,
		  			rownumbers:true,
		  			width: document.body.clientWidth-20,
		  			height: 450,
		  		    columns:columns
				});
			}
		});
	}
	
	//选择指标
	function selectIndicator(){
		var url = "${baseURL}/audit/queryIndicatorSelect";
		openWin("指标选择", url, "1000", "560", setIndicatorListData);
		
	}
	
	function setIndicatorListData(indicator){
		$("#indicatorListData").val(indicator);
	}
	
	function queryAreasByParent(obj){
		$.getJSON("${baseURL}/area/queryAreasByParent/" + obj.value, function(json){
			$("#areaId3").empty();
			$("#areaId3").append("<option value=''>请选择..</option>");
			$.each(json, function(i, area){
				$("#areaId3").append("<option value='" + area.id + "'>" + area.areaName + "</option>");
			});
		});
	}
	
	function clearInput(){
		$("#nodata").css("display", "");
		$("#dataList").css("display", "none");
		$("#dataList table").empty();
	}

</script>

<%@ include file="/static/include/bottom.jsp"%>